package com.systemic.controller;

import com.systemic.core.ResponseResult;
import com.systemic.pojo.FriendApply;
import com.systemic.service.FriendApplyService;
import com.systemic.vo.ReceiveApply;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: FriendApplyController
 * @Description: 好友申请
 * @Author:
 * @CreateTime: 2023-12-29 10:19
 * @Version:
 **/

@RestController
@RequestMapping("/friendApply")
public class FriendApplyController {

    @Resource
    private FriendApplyService friendApplyService;

    /**
     * 发送好友申请
     * @param friendApply
     * @return
     */
    @PostMapping("/send")
    public ResponseResult<String> sendApply(@RequestBody FriendApply friendApply){
        friendApplyService.insert(friendApply);
        return ResponseResult.success("已发送好友申请");
    }

    /**
     * 接收好友申请
     * @param uid
     * @return
     */
    @GetMapping("/receive/{uid}")
    public ResponseResult<List<ReceiveApply>> receiveApply(@PathVariable("uid") Integer uid){
        List<ReceiveApply> receiveApplies = friendApplyService.selectListById(uid);
        if (receiveApplies==null){
            return ResponseResult.failed("没有查询到好友申请");
        }
        return ResponseResult.success(receiveApplies);
    }

    /**
     * 用户A 同意 用户B 发起的好友申请  涉及 修改业务（friendApply表）、新增业务（friend表）
     * @param friendApply
     * @return
     */
    @PostMapping("/agree")
    public ResponseResult<String> agree(@RequestBody FriendApply friendApply){
        int rows = friendApplyService.updateFriendApply(friendApply);
        if (rows==0){
            return ResponseResult.failed("失败");
        }
        return ResponseResult.success("已同意");
    }


    /**
     * 忽略好友申请
     * @param friendApply
     * @return
     */
    @PostMapping("/ignore")
    public ResponseResult<String> ignore(@RequestBody FriendApply friendApply){
        int rows = friendApplyService.ignoreFriendApply(friendApply);
        if (rows==0){
            return ResponseResult.failed("失败");
        }
        return ResponseResult.success("已忽略");

    }

}
